package com.cby.android.base.accessibility

import android.accessibilityservice.AccessibilityService
import android.accessibilityservice.GestureDescription
import android.graphics.Path
import android.os.Build
import androidx.annotation.RequiresApi
import com.cby.util.lib.util.CbyLogUtils

/**
 * @description: ClickUtils
 * @author: ChenBaoYang
 * @createDate: 2022/7/20 5:08 下午
 */
object ClickUtils {

    @RequiresApi(Build.VERSION_CODES.N)
    fun click(accessibilityService: AccessibilityService, x: Float, y: Float) {
        CbyLogUtils.flog("chenby", "click: ($x, $y)")
        val builder = GestureDescription.Builder()
        val path = Path()
        path.moveTo(x, y)
        path.lineTo(x, y)
        builder.addStroke(GestureDescription.StrokeDescription(path, 0, 1))
        val gesture = builder.build()
        accessibilityService.dispatchGesture(gesture, object : AccessibilityService.GestureResultCallback() {
            override fun onCancelled(gestureDescription: GestureDescription) {
                super.onCancelled(gestureDescription)
            }

            override fun onCompleted(gestureDescription: GestureDescription) {
                super.onCompleted(gestureDescription)
            }
        }, null)
    }
}